/*     */ package com.yc.dao.station;
/*     */ 
/*     */ import btsm.bean.dbConnector;
/*     */ import com.yc.dao.model.TrafficInfoBO;
/*     */ import com.yc.util.FormateSQL;
/*     */ import com.yc.util.ListContentsBFO;
/*     */ import java.sql.ResultSet;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ 
/*     */ public class TrafficInfoDAO
/*     */ {
/*  21 */   private static final Log log = LogFactory.getLog(TrafficInfoDAO.class);
/*  22 */   private SimpleDateFormat open = new SimpleDateFormat("yyyy-MM-dd");
/*  23 */   private SimpleDateFormat fresh = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
/*  24 */   private dbConnector dbcon = null;
/*     */ 
/*  26 */   private void dbConInit() { if (this.dbcon == null)
/*  27 */       this.dbcon = new dbConnector(); }
/*     */ 
/*     */   private void dbConClose()
/*     */   {
/*  31 */     if (this.dbcon != null)
/*  32 */       this.dbcon.closeAll();
/*  33 */     this.dbcon = null;
/*     */   }
/*     */ 
/*     */   public ListContentsBFO getTrafficInfoList(Map condition)
/*     */   {
/*  38 */     ListContentsBFO bfo = new ListContentsBFO();
/*  39 */     int start = Integer.parseInt(condition.get("start").toString());
/*  40 */     int limit = Integer.parseInt(condition.get("limit").toString());
/*  41 */     String strBtscode = condition.get("BTS_CODE").toString();
/*  42 */     ResultSet rs = null;
/*  43 */     List list = new ArrayList();
/*     */     try
/*     */     {
/*  46 */       dbConInit();
/*  47 */       String strSQL = " select count(id) from trafficinfo where btscode = '" + strBtscode + "' ";
/*  48 */       log.info(strSQL);
/*  49 */       rs = this.dbcon.execQuery(strSQL);
/*  50 */       if (rs.next()) {
/*  51 */         bfo.setTotalSize(rs.getInt(1));
/*     */       }
/*  53 */       strSQL = " select * from trafficinfo where btscode ='" + strBtscode + "' limit " + start + ", " + limit;
/*  54 */       log.info(strSQL);
/*  55 */       rs = this.dbcon.execQuery(strSQL);
/*  56 */       while (rs.next()) {
/*  57 */         TrafficInfoBO bo = new TrafficInfoBO();
/*  58 */         bo.setId(rs.getString("id"));
/*  59 */         bo.setBtscode(rs.getString("btscode"));
/*  60 */         bo.setBtsname(rs.getString("btsname"));
/*  61 */         bo.setRoad(rs.getString("road"));
/*  62 */         bo.setRoadway(rs.getString("roadway"));
/*  63 */         bo.setDistanceC(rs.getString("distanceC"));
/*  64 */         bo.setArrivaltimeC(rs.getString("arrivaltimeC"));
/*  65 */         bo.setDistanceP(rs.getString("distanceP"));
/*  66 */         bo.setArrivaltimeP(rs.getString("arrivaltimeP"));
/*  67 */         bo.setRefreshtime(rs.getDate("refreshtime"));
/*  68 */         bo.setMemo(rs.getString("memo"));
/*  69 */         list.add(bo);
/*     */       }
/*  71 */       bfo.setData(list.toArray());
/*     */     }
/*     */     catch (Exception e) {
/*  74 */       e.printStackTrace();
/*  75 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/*  78 */       dbConClose();
/*     */     }
/*  80 */     return bfo;
/*     */   }
/*     */ 
/*     */   public boolean saveTrafficInfoBO(TrafficInfoBO bo)
/*     */   {
/*  85 */     log.info("添加--交通状况---开始");
/*  86 */     boolean flag = true;
/*     */     try
/*     */     {
/*  89 */       dbConInit();
/*  90 */       StringBuffer sqlBuf = new StringBuffer();
/*  91 */       sqlBuf.append(" insert into trafficinfo ( btscode, btsname, road,roadway,");
/*  92 */       sqlBuf.append(" distanceC, arrivaltimeC, distanceP, arrivaltimeP,");
/*  93 */       sqlBuf.append(" refreshtime,registtime, memo ) values ( ");
/*  94 */       sqlBuf.append(" '" + bo.getBtscode() + "' ,");
/*  95 */       sqlBuf.append(" '" + bo.getBtsname() + "' ,");
/*  96 */       sqlBuf.append(" '" + bo.getRoad() + "' ,");
/*  97 */       sqlBuf.append(" '" + bo.getRoadway() + "' ,");
/*  98 */       sqlBuf.append(" '" + bo.getDistanceC() + "' ,");
/*  99 */       sqlBuf.append(" '" + bo.getArrivaltimeC() + "' ,");
/* 100 */       sqlBuf.append(" '" + bo.getDistanceP() + "' ,");
/* 101 */       sqlBuf.append(" '" + bo.getArrivaltimeP() + "' ,");
/* 102 */       sqlBuf.append(" '" + this.fresh.format(new Date()) + "' ,");
/* 103 */       sqlBuf.append(" '" + this.open.format(new Date()) + "' ,");
/* 104 */       sqlBuf.append(" '" + bo.getMemo() + "' )");
/* 105 */       log.info(sqlBuf.toString());
/* 106 */       this.dbcon.execUpdate(sqlBuf.toString());
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 110 */       flag = false;
/* 111 */       e.printStackTrace();
/* 112 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 115 */       dbConClose();
/*     */     }
/* 117 */     log.info("添加--交通状况---结束");
/* 118 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean updateTrafficInfoBO(TrafficInfoBO bo)
/*     */   {
/* 123 */     log.info("修改--交通状况---开始");
/* 124 */     boolean flag = true;
/*     */     try
/*     */     {
/* 127 */       dbConInit();
/* 128 */       StringBuffer sqlBuf = new StringBuffer();
/* 129 */       sqlBuf.append(" update trafficinfo  set ");
/* 130 */       sqlBuf.append(" road = '" + bo.getRoad() + "' ,");
/* 131 */       sqlBuf.append(" roadway = '" + bo.getRoadway() + "' ,");
/* 132 */       sqlBuf.append(" distanceC = '" + bo.getDistanceC() + "' ,");
/* 133 */       sqlBuf.append(" arrivaltimeC = '" + bo.getArrivaltimeC() + "' ,");
/* 134 */       sqlBuf.append(" distanceP = '" + bo.getDistanceP() + "' ,");
/* 135 */       sqlBuf.append(" arrivaltimeP = '" + bo.getArrivaltimeP() + "' ,");
/* 136 */       sqlBuf.append(" refreshtime = '" + this.fresh.format(new Date()) + "' ,");
/* 137 */       sqlBuf.append(" memo = '" + bo.getMemo() + "' ");
/* 138 */       sqlBuf.append(" where id='" + bo.getId() + "'");
/* 139 */       log.info(sqlBuf.toString());
/* 140 */       this.dbcon.execUpdate(sqlBuf.toString());
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 144 */       flag = false;
/* 145 */       e.printStackTrace();
/* 146 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 149 */       dbConClose();
/*     */     }
/* 151 */     log.info("修改--交通状况---结束");
/* 152 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean deleteTrafficInfoBO(String strID)
/*     */   {
/* 157 */     log.info("删除--交通状况---开始");
/* 158 */     boolean flag = true;
/*     */     try
/*     */     {
/* 161 */       dbConInit();
/* 162 */       StringBuffer sqlBuf = new StringBuffer();
/* 163 */       sqlBuf.append(" delete from trafficinfo   ");
/* 164 */       sqlBuf.append(" where id='" + strID + "'");
/* 165 */       log.info(sqlBuf.toString());
/* 166 */       this.dbcon.execUpdate(sqlBuf.toString());
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 170 */       flag = false;
/* 171 */       e.printStackTrace();
/* 172 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 175 */       dbConClose();
/*     */     }
/* 177 */     log.info("删除--交通状况---结束");
/* 178 */     return flag;
/*     */   }
/*     */ 
/*     */   public ListContentsBFO getTrafficInfoByBtsName(Map condition)
/*     */   {
/* 183 */     ListContentsBFO bfo = new ListContentsBFO();
/* 184 */     int start = Integer.parseInt(condition.get("start").toString());
/* 185 */     int limit = Integer.parseInt(condition.get("limit").toString());
/* 186 */     String strBtsName = condition.get("btsName").toString();
/* 187 */     ResultSet rs = null;
/* 188 */     List list = new ArrayList();
/*     */     try
/*     */     {
/* 191 */       dbConInit();
/* 192 */       Object objRegistBeginTime = condition.get("registBeginTime");
/* 193 */       Object objRegistEndTime = condition.get("registEndTime");
/*     */ 
/* 195 */       String strSQL = " select count(id) from trafficinfo where btsname like '%" + strBtsName + "%' ";
/* 196 */       strSQL = FormateSQL.getFormateSQL(objRegistBeginTime, objRegistEndTime, strSQL);
/* 197 */       log.info(strSQL);
/* 198 */       rs = this.dbcon.execQuery(strSQL);
/* 199 */       if (rs.next()) {
/* 200 */         bfo.setTotalSize(rs.getInt(1));
/*     */       }
/* 202 */       strSQL = " select * from trafficinfo where btsname like '%" + strBtsName + "%' ";
/* 203 */       strSQL = FormateSQL.getFormateSQL(objRegistBeginTime, objRegistEndTime, strSQL);
/* 204 */       strSQL = strSQL + "limit " + start + ", " + limit;
/* 205 */       log.info(strSQL);
/* 206 */       rs = this.dbcon.execQuery(strSQL);
/* 207 */       while (rs.next()) {
/* 208 */         TrafficInfoBO bo = new TrafficInfoBO();
/* 209 */         bo.setId(rs.getString("id"));
/* 210 */         bo.setBtscode(rs.getString("btscode"));
/* 211 */         bo.setBtsname(rs.getString("btsname"));
/* 212 */         bo.setRoad(rs.getString("road"));
/* 213 */         bo.setRoadway(rs.getString("roadway"));
/* 214 */         bo.setDistanceC(rs.getString("distanceC"));
/* 215 */         bo.setArrivaltimeC(rs.getString("arrivaltimeC"));
/* 216 */         bo.setDistanceP(rs.getString("distanceP"));
/* 217 */         bo.setArrivaltimeP(rs.getString("arrivaltimeP"));
/* 218 */         bo.setRefreshtime(rs.getDate("refreshtime"));
/* 219 */         bo.setMemo(rs.getString("memo"));
/* 220 */         list.add(bo);
/*     */       }
/* 222 */       bfo.setData(list.toArray());
/*     */     }
/*     */     catch (Exception e) {
/* 225 */       e.printStackTrace();
/* 226 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 229 */       dbConClose();
/*     */     }
/* 231 */     return bfo;
/*     */   }
/*     */ 
/*     */   public List export(String strBtsName, String strRegistBeginTime, String strRegistEndTime)
/*     */   {
/* 236 */     ResultSet rs = null;
/* 237 */     List list = new ArrayList();
/*     */     try
/*     */     {
/* 240 */       dbConInit();
/* 241 */       String strSQL = " select * from trafficinfo where btsname like '%" + strBtsName + "%'  ";
/* 242 */       strSQL = FormateSQL.getFormateSQL(strRegistBeginTime, strRegistEndTime, strSQL);
/* 243 */       log.info(strSQL);
/* 244 */       rs = this.dbcon.execQuery(strSQL);
/* 245 */       while (rs.next()) {
/* 246 */         TrafficInfoBO bo = new TrafficInfoBO();
/* 247 */         bo.setId(rs.getString("id"));
/* 248 */         bo.setBtscode(rs.getString("btscode"));
/* 249 */         bo.setBtsname(rs.getString("btsname"));
/* 250 */         bo.setRoad(rs.getString("road"));
/* 251 */         bo.setRoadway(rs.getString("roadway"));
/* 252 */         bo.setDistanceC(rs.getString("distanceC"));
/* 253 */         bo.setArrivaltimeC(rs.getString("arrivaltimeC"));
/* 254 */         bo.setDistanceP(rs.getString("distanceP"));
/* 255 */         bo.setArrivaltimeP(rs.getString("arrivaltimeP"));
/* 256 */         bo.setRefreshtime(rs.getDate("refreshtime"));
/* 257 */         bo.setMemo(rs.getString("memo"));
/* 258 */         list.add(bo);
/*     */       }
/*     */     }
/*     */     catch (Exception e) {
/* 262 */       e.printStackTrace();
/* 263 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 266 */       dbConClose();
/*     */     }
/* 268 */     return list;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.dao.station.TrafficInfoDAO
 * JD-Core Version:    0.6.2
 */